package com.my.study.guava;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

import java.nio.charset.Charset;

/**
 * 布隆过滤器
 *
 * @author: yidujun
 * @create: 2021/04/12 19:28
 */
public class BloomFilterTest {

    public static void main(String[] args) {
        /**
         * 创建一个插入对象为1亿，误报率为0.01%的布隆过滤器
         *
         * 不存在一定不存在
         * 存在不一定存在
         */
        BloomFilter<CharSequence> bloomFilter = BloomFilter.create(Funnels.stringFunnel(Charset.forName("utf-8")),
                100000000,
                0.0001);

        bloomFilter.put("死");
        bloomFilter.put("磕");
        bloomFilter.put("Redis");

        System.out.println(bloomFilter.mightContain("Redis"));
        System.out.println(bloomFilter.mightContain("死"));
        System.out.println(bloomFilter.mightContain("Java"));
        System.out.println(bloomFilter.mightContain("磕"));

    }

}
